<?php
/*
Cogumelo v0.1 - Map-Experience
Copyright (C) 2009 Innoto Gestión para el Desarrollo Social S.L. <mapinfo@map-experience.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
USA.
*/

//
// UserAdmin Access Controller
//
require_once("Classes/Controllers/Access/AccessController.inc");
require_once("Classes/Controllers/Session/UserAdminSessionController.inc");
require_once("Classes/Controllers/Data/UseradminController.inc");
require_once("Classes/Model/VO/UseradminVO.inc");


class UserAdminAccessController extends AccessController 
{

	//
	// Constructor
	//
function UserAdminAccesscontroller()
 {  
 	parent::__construct();
 	$this->sessioncontrol=new UserAdminSessionController();
 	$this->sessiondata=$this->sessioncontrol->getUser();
 }


 /*
  * Is current User a Loged Administrator?
  */
 function isAdmin()
 {
    if($this->sessiondata) return true;
    else return false;
 }

 
 
 //
 // Login an Admin User
 //
 function UserAdminLogin($username, $passwd)
 {
  $usercontrol= new UserAdminController();
  
  $user=new UserAdminVO();
  $user->setLogin($username);
  $user->setPasswd($passwd);  
  if($logeduser = $usercontrol->AuthenticateUseradmin($user))
  {
    
  	   $this->sessioncontrol->setUser($logeduser);
  	   $this->logcontrol->addLogLine("Accepted UserAdmin authentication: user ".$username." is logged", 2);
  	   return true;	
            
  }          
  else {
  	    $this->logcontrol->addLogLine("Failed UserAdmin authentication: user ".$username, 2);
  	    return false;
  }
 }
 
 
 
 
 
 //
 // Logout a User
 //
 function Logout()
 { 	
   if($currentuser = $this->sessioncontrol->getUser())
   {   	
   	$this->sessioncontrol->delUser();
   	$this->logcontrol->addLogLine("UserAdmin ".$currentuser->getLogin()." Logged out", 2);
   	return true;
   }   
   else { $this->logcontrol->addLogLine("Unable to Logout", 2); return false; }
   
 }
 
 
}
?>